﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace teach
{
    public class Multiplication : Question, IOperation
    {
        public Multiplication()
        {
            m_message = "Multiplication";
        }

        public int First { get; set; }
        public int Second { get; set; }
        public int OperationAnswer { get; set; }
        public int EmptyField { get; set; }
        public string Sign
        {
            get
            {
                return "X";
            }
        }

        public override object Answer
        {
            get
            {
                int result = OperationAnswer;
                if (EmptyField == 1)
                {
                    result = First;
                }
                else if (EmptyField == 2)
                {
                    result = Second;
                }
                return result;
            }
        }

        public override bool CheckAnswer(object userAnswer)
        {
            return (userAnswer.ToString().Trim() == Answer.ToString());
        }

        public override void GenerateValues(Preference pref)
        {
            this.Timeout = pref.Timeout * 1000;
            EmptyField = TeachController.RND.Next(4);
            if (EmptyField == 3)
            {
                EmptyField = 0;
            }
            First = TeachController.RND.Next(pref.Max - pref.Min) + pref.Min;
            Second = TeachController.RND.Next(pref.Max - pref.Min) + pref.Min;
            OperationAnswer = First * Second;
        }
    }
}
